package leetcode;

import java.util.Collections;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 反转字符串中的单词 III
 * @date 2022/5/25 8:37
 */
public class Code557 {

    public String reverseWords(String s) {
        int length = s.length();
        if(length==0){
            return null;
        }
        String[] s1 = s.split(" ");
        String str = "";
        for (int i = 0; i <s1.length ; i++) {
            String s2 = s1[i];
            for (int j=s2.length()-1;j>=0;j--){
                str += s2.charAt(j);
            }
            str+= " ";
        }
        return str.trim();
    }


    public String reverseWords2(String s) {
        int length = s.length();
        if(length==0){
            return null;
        }
        StringBuffer string = new StringBuffer();
        String[] s1 = s.split(" ");
        for (int i = 0; i < s1.length; i++) {
            string.append(new StringBuffer(s1[i]).reverse().toString());
            string.append(" ");
        }
        return string.toString().trim();
    }


    public static void main(String[] args) {
        String s = "Let's take LeetCode contest";

        System.out.println(new Code557().reverseWords2(s));
    }
}
